<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('freelancers', function (Blueprint $table) {
            if (! Schema::hasColumn('freelancers', 'weixin_openid')) {
                $table->string('weixin_openid')
                    ->nullable()
                    ->after('phone')
                    ->comment('微信openid');
            }

            $table->index('weixin_openid', 'freelancers_weixin_openid_index');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('freelancers', function (Blueprint $table) {
            if (Schema::hasColumn('freelancers', 'weixin_openid')) {
                $table->dropIndex('freelancers_weixin_openid_index');
                $table->dropColumn('weixin_openid');
            }
        });
    }
};
